<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Returns a single file matching the criteria</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mongogridfs.find.html">MongoGridFS::find</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mongogridfs.get.html">MongoGridFS::get</a></div>
 <div class="up"><a href="class.mongogridfs.html">MongoGridFS</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="mongogridfs.findone" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">MongoGridFS::findOne</h1>
  <p class="verinfo">(PECL mongo &gt;=0.9.0)</p><p class="refpurpose"><span class="refname">MongoGridFS::findOne</span> &mdash; <span class="dc-title">Returns a single file matching the criteria</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-mongogridfs.findone-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type"><a href="class.mongogridfsfile.html" class="type MongoGridFSFile">MongoGridFSFile</a></span> <span class="methodname"><strong>MongoGridFS::findOne</strong></span>
    ([ <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$query</code><span class="initializer"> = array()</span></span>
   [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$fields</code><span class="initializer"> = array()</span></span>
  ]] )</div>

 </div>


 <div class="refsect1 parameters" id="refsect1-mongogridfs.findone-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>

      <em><code class="parameter">query</code></em>
     </dt>

     <dd>

      <p class="para">
       The filename or criteria for which to search.
      </p>
     </dd>

       
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-mongogridfs.findone-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns a <a href="class.mongogridfsfile.html" class="classname">MongoGridFSFile</a> or <strong><code>NULL</code></strong>.
  </p>
 </div>

 
 <div class="refsect1 examples" id="refsect1-mongogridfs.findone-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-1474">
   <p><strong>Example #1 <span class="methodname"><strong>MongoGridFS::findOne()</strong></span> example</strong></p>
   <div class="example-contents"><p>
    Example demonstrating how to find a single file from the MongoGridFS.
   </p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$downloads&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$mongo</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">my_db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getGridFS</span><span style="color: #007700">(</span><span style="color: #DD0000">'downloads'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$downloads</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">storeFile</span><span style="color: #007700">(</span><span style="color: #DD0000">'filename.tgz'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$download&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$downloads</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">findOne</span><span style="color: #007700">(</span><span style="color: #DD0000">'filename.tgz'</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;instance&nbsp;of&nbsp;MongoGridFSFile<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$download</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>
    See <a href="class.mongogridfsfile.html" class="classname">MongoGridFSFile</a> for more information about how to work with files.
   </p></div>
   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
MongoGridFSFile Object
(
    [file] =&gt; Array
        (
            [_id] =&gt; MongoId Object
                (
                )

            [filename] =&gt; filename.tgz
            [uploadDate] =&gt; MongoDate Object
                (
                    [sec] =&gt; 1274288014
                    [usec] =&gt; 467000
                )

            [chunkSize] =&gt; 262144
            [md5] =&gt; d41d8cd98f00b204e9800998ecf8427e
        )

    [gridfs:protected] =&gt; MongoGridFS Object
        (
            [chunks] =&gt; MongoCollection Object
                (
                )

            [filesName:protected] =&gt; downloads.files
            [chunksName:protected] =&gt; downloads.chunks
        )

)
</pre></div>
   </div>
  </div>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mongogridfs.find.html">MongoGridFS::find</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mongogridfs.get.html">MongoGridFS::get</a></div>
 <div class="up"><a href="class.mongogridfs.html">MongoGridFS</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
